import {reqPersonalList} from "../api";

const state = {
  player:[],
  playertable: [],
  playername: [],
  playerkills: [],
  playerAssists: [],
  playerDeaths: [],
  playerCnumber: [], // 出场次数
  KDA: [],
  MVPnum:[],
  PKprice: [], //对位经济差
  playermax: []
}
const mutations = {
  GETPERSONLIST(state,player){
    state.player = player;
  }
}
const actions = {
  async getPersonList({commit}){
    let result = await reqPersonalList();
    if (result){
      commit("GETPERSONLIST",result)
    }
  }
}
const getters = {
  getPersonTable(state){
    state.player.map((item)=>{
      let people = []
      people.push(item.teamMember)
      people.push(item.location)
      people.push(item.totalKills)
      state.playertable.push(people)
    })
    return state.playertable
  },
  getPlayerName(state){
    state.player.map((item)=>{
      state.playername.push(item.teamMember)
    })
    return state.playername
  },
  getPlayerKills(state){
    state.player.map((item)=>{
      state.playerkills.push(item.totalKills)
    })
    return state.playerkills
  },
  getPlayerAssists(state){
    state.player.map((item)=>{
      state.playerAssists.push(item.totalDeaths)
    })
    return state.playerAssists
  },
  getPlayerDeaths(state){
    state.player.map((item)=>{
      state.playerDeaths.push(item.totalAssists)
    })
    return state.playerDeaths
  },
  getPlayerCCnum(state){
    state.player.map((item)=>{
      state.playerCnumber.push(item.frequency)
    })
    return state.playerCnumber
  },
  getPlayerKDA(state){
    state.player.map((item)=>{
      state.KDA.push(item.KDA)
    })
    return state.KDA
  },
  getPlayerMVP(state){
    state.player.map((item)=>{
      state.MVPnum.push(item.MVPTimes)
    })
    return state.MVPnum
  },
  getPlayerPK(state){
    state.player.map((item)=>{
      state.PKprice.push(item.matchmakingeconomy)
    })
    return state.PKprice
  },
  getPlayerMax(state){
    let maxKDA = []
    let maxMVP = []
    let maxMatchmakingEconomy = []
    let one
    let two
    let three
    state.player.map((item)=>{
      maxKDA.push(item.KDA)
      maxMVP.push(item.MVPTimes)
      maxMatchmakingEconomy.push(item.matchmakingeconomy)

      one = Math.max(...maxKDA)
      two = Math.max(...maxMVP)
      three = Math.max(...maxMatchmakingEconomy)
    })
    state.player.map((item)=>{
      let KK = []
      for (let i in item){
        KK.push(item[i])
      }

      if (KK[0]===one){
        state.playermax.splice(0,1,[KK[1],one])
      }
      if(KK[6] === two){
        state.playermax.push([KK[1],two])
      }
      if(KK[9] === three){
        state.playermax.push([KK[1],three])
      }
    })
    return state.playermax
  },
}

export default {
  state,
  mutations,
  actions,
  getters
}
